﻿<!--
	========================================================================
	 NQ Software Development Kit Component
	
	 Homepage: http://www.awzhome.de/
	========================================================================
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Software Development Kit Component.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	========================================================================
-->

<UserControl
	x:Class="AWZhome.NQsdk.Visual.LogMessageView"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:nq="clr-namespace:AWZhome.NQ.Core;assembly=NQCore"
	xmlns:nqcs="clr-namespace:AWZhome.NQ.CommonServices;assembly=NQCommServ.Interface"
	xmlns:nqsdk="clr-namespace:AWZhome.NQsdk.Services"
	xmlns:nqsdkhelpers="clr-namespace:AWZhome.NQsdk.Helpers"
	xmlns:nqsdkvisual="clr-namespace:AWZhome.NQsdk.Visual"
	mc:Ignorable="d" 
	d:DesignHeight="391" d:DesignWidth="610">

	<UserControl.Resources>

		<!-- ListViewItem image style -->
		<Style x:Key="LogMessageIconStyle" TargetType="{x:Type Image}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding Level}" Value="Debug">
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/Debug.png, Type=ImageSource}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Info">
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/Information.png, Type=ImageSource}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Warning">
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/Warning.png, Type=ImageSource}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Error">
					<Setter Property="Source" Value="{nqcs:ResourceBinding Component=NQsdkImages, Name=/Images/CriticalError.png, Type=ImageSource}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<!-- ListViewItem text styles -->
		<Style x:Key="LogMessageTextColorStyle" TargetType="{x:Type ListViewItem}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding Level}" Value="Debug">
					<Setter Property="Foreground" Value="DimGray" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Info">
					<Setter Property="Foreground" Value="Black" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Warning">
					<Setter Property="Foreground" Value="DarkBlue" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Error">
					<Setter Property="Foreground" Value="DarkRed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<Style x:Key="LogMessageTitleStyle" TargetType="{x:Type TextBlock}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding Level}" Value="Debug">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Level.Debug}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Info">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Level.Info}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Warning">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Level.Warning}" />
				</DataTrigger>
				<DataTrigger Binding="{Binding Level}" Value="Error">
					<Setter Property="Text" Value="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Level.Error}" />
				</DataTrigger>
			</Style.Triggers>
		</Style>

		<!-- Template for 1st column of ListViewItems -->
		<DataTemplate x:Key="LogMessageDataTemplate" DataType="{x:Type nqsdkhelpers:LogMessage}">
			<StackPanel Orientation="Horizontal">
				<Image Width="16" Height="16" Style="{Binding Source={StaticResource LogMessageIconStyle}}" />
				<TextBlock Style="{Binding Source={StaticResource LogMessageTitleStyle}}" Margin="3,0,0,0" />
			</StackPanel>
		</DataTemplate>

	</UserControl.Resources>

	<Grid>
		<nqcs:BarHostControl Name="toolbarHost">
			<ListView ItemsSource="{Binding}" ItemContainerStyle="{Binding Source={StaticResource LogMessageTextColorStyle}}">
				<ListView.View>
					<GridView>
						<GridViewColumn Width="50" Header="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Column.ID}"
									DisplayMemberBinding="{Binding MessageID}" />
						<GridViewColumn Width="80" Header="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Column.Level}"
									CellTemplate="{Binding Source={StaticResource LogMessageDataTemplate}}" />
						<GridViewColumn Width="150" Header="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Column.Timestamp}"
									DisplayMemberBinding="{Binding Timestamp}" />
						<GridViewColumn Width="300" Header="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Column.SourceService}"
									DisplayMemberBinding="{Binding SourceService}" />
						<GridViewColumn Width="600" Header="{nqcs:ResourceBinding Component=NQsdk, Name=LogMessageView.Column.Message}"
									DisplayMemberBinding="{Binding Message}" />
					</GridView>
				</ListView.View>
			</ListView>
		</nqcs:BarHostControl>
	</Grid>
</UserControl>
